<!DOCTYPE html>
<html class="x-admin-sm">
{block name="include"}{include file="head" /}{/block}
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <input type="hidden" name="id" value="{$user.id}">
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">账号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="user_name" name="user_name" required="" lay-verify="user_name"
                                   autocomplete="off" class="layui-input" value="{$user.user_name}" disabled="">
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label">
                            <span class="x-red">*</span>旧密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="mima" name="oldpass" required="" lay-verify="required" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_pass" class="layui-form-label">
                            <span class="x-red">*</span>新密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="L_pass" name="user_password" required="" lay-verify="pass" autocomplete="off" class="layui-input"></div>
                        <div class="layui-form-mid layui-word-aux">6到16个字符</div></div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label">
                            <span class="x-red">*</span>确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" id="L_repass" name="repass" required="" lay-verify="repass" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="save" lay-submit="">修改</button></div>
                </form>
            </div>
        </div>
        <script>layui.use(['form', 'layer'],
            function() {
                $ = layui.jquery;
                var form = layui.form,
                layer = layui.layer;
                //自定义验证规则
                form.verify({
                    user_name: function(value) {
                        if (value.length < 3) {
                            return '账号至少得3位数';
                        }
                    },
                    pass: [/(.+){6,12}$/, '密码必须6到12位'],
                    repass: function(value) {
                        if ($('#L_pass').val() != $('#L_repass').val()) {
                            return '两次密码不一致';
                        }
                    },


                });
                //监听提交
                form.on('submit(save)',
                function(data) {

                    $.ajax({
                        url: "{:url('admin/User/password')}",
                        type:'post',
                        data:data.field,
                        success:function (callback) {
                            if (callback.msg == 200){
                                layer.msg('修改成功',{icon:6});
                                setTimeout(function () {
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                },1200);
                            }else {
                                layer.msg(callback.msg, {icon: 5})
                            }

                        }
                    });
                    return false;

                });

            });</script>

    </body>

</html>